<template>
  <div class="root">
    <!-- 涂鸦推荐 -->
    <div>
      <div class="pet_list_head">
        <div class="pet_list_name">
          <div
            class="iconfont pet_nav_kantuya pet_more_list_block_line_ico"
            :style="{margin:'-2vw 2vw 0 0'}"
          ></div>
          <h4 class="pet_more_list_block_line_font" :style="{color:'#6F68DF'}">涂鸦推荐</h4>
        </div>
        <div class="pet_type">看涂鸦</div>
      </div>
      <div class="scrawlImg">
        <div v-if="index<6" v-for="(item,index) in scrawlList" :key="index">
          <img :src="item.picture" alt>
        </div>
      </div>
    </div>
    <!-- 萌专题 -->
    <div v-for="(pickItem,index) in pickList" :key="index">
      <div class="pet_list_head">
        <div class="pet_list_name">
          <img :src="pickItem.admin.avatar" alt>
          <p v-text="pickItem.admin.name"></p>
        </div>
        <div class="pet_type pet_type1" v-text="pickItem.article_tags.substring(0,20)"></div>
      </div>

      <!-- 跳转详情点击事件 -->
      <div @click="goToDetail(pickItem)">
        <div v-if="pickItem.picture3==''" class="pet_list_content">
          <div class="pet_list_title">
            <h4 v-text="pickItem.title"></h4>
            <p v-text="pickItem.intro"></p>
          </div>
          <img :src="pickItem.picture1" alt>
        </div>

        <div v-if="pickItem.picture3!==''" class="pet_list_content pet_list_content2">
          <div>
            <h4 v-text="pickItem.title"></h4>
          </div>
          <div class="pet_picture">
            <img :src="pickItem.picture1" alt>
            <img :src="pickItem.picture2" :style="{height:'25vw'}" alt>
            <img :src="pickItem.picture3" alt>
          </div>
          <p v-text="pickItem.intro"></p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data: function() {
    return {
      page: 1,
      scrawlList: [],
      pickList: [],
      loadingMore: false
    };
  },
  created() {
    // 看涂鸦
    this.scrawlContent();
    // 涨知识
    this.picklist();
    window.onscroll = this.didScroll;
  },
  methods: {
    // 跳转到详情
    goToDetail(value) {
      this.$router.push({path:"/a/articledecommenlist",query:{article_id:value.id}});
      // 存储到本地
      window.localStorage.setItem('pet_key',JSON.stringify(value))
    },
    // 看涂鸦
    scrawlContent: function() {
      var that = this;
      this.$http.get("/pet/v2/petalbumrecommendlist").then(function(data) {
        console.log(data);
        that.scrawlList = data.body.data.list;
      });
    },
    picklist: function() {
      var that = this;
      this.$http
        .get("/pet/v2/indexarticlerecommendlist?page=" + this.page)
        .then(function(data) {
          that.pickList = data.body.data.list;
          console.log(that.pickList);
        });
    },
    didScroll() {
      // 获取滚动的距离
      var contentScrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      // 获取屏幕的高度
      var screenHeight = window.innerHeight;
      // 获取内容的高度
      var contentHeight = document.body.clientHeight;
      if (contentScrollTop + screenHeight > contentHeight - 100) {
        if (this.loadingMore == false) {
          this.loadMore();
        }
      }
    },

    loadMore() {
      this.loadingMore = true;
      this.page += 1;

      var that = this;
      this.$http
        .get("/pet/v2/indexarticlerecommendlist?page=" + this.page)
        .then(function(data) {
          that.pickList = that.pickList.concat(data.body.data.list);
          that.loadingMore = false;
          console.log(that.pickList);
        });
    }
  }
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
img {
  vertical-align: bottom;
}
.root {
  background: #fff;
  padding: 3vw 5vw;
}
.root > div {
  margin: 2vw 0;
  border-bottom: 1px solid #eee;
}

/* 看涂鸦 */

.pet_type {
  position: relative;
  font-size: 3.2vw;
  color: #6f68df;
  margin-right: 2vw;
}
/* FE9700 */
.pet_type::before {
  display: block;
  content: "";
  width: 0.7vw;
  height: 140%;
  background: #6f68df;
  position: absolute;
  right: -2vw;
  top: -20%;
}
.scrawlImg {
  display: flex;
  width: 100%;
  flex-flow: row wrap;
  justify-content: space-between;
}
.scrawlImg img {
  margin-top: 2vw;
  width: 28vw;
  height: 28vw;
}
/* 涨知识 */
.pet_type1 {
  color: #f26765;
}
.pet_type1::before {
  background: #f26765;
}
.pet_list_head,
.pet_picture {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pet_picture {
  align-items: flex-start;
}
.pet_list_name {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.pet_list_name img {
  width: 8vw;
  height: 8vw;
  border-radius: 50%;
  margin-right: 2vw;
}
.pet_list_name p {
  font-size: 3.2vw;
  color: #757575;
}

.pet_list_content {
  display: flex;
  justify-content: space-between;
  margin: 2vw 0;
}
.pet_list_content .pet_list_title {
  width: 60vw;
  max-width: 60vw;
  /* border: 1px solid red; */
}
.pet_list_content p {
  color: #757575;
  width: 60vw;
  font-size: 3.3vw;
  margin: 2vw 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.pet_list_content img {
  width: 29vw;
  height: 17vw;
}
.pet_list_content2 {
  display: flex;
  flex-flow: column nowrap;
}
.pet_list_content2 h4,
.pet_list_content2 p {
  width: 100%;
  /* border: 1px solid red; */
}
.pet_picture {
  margin-top: 2vw;
}
.pet_picture img {
  width: 29vw;
  height: 21vw;
}
</style>